//plugin jquery.cookies
jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
if(typeof ucenter_domain=="undefined") ucenter_domain="https://passport.zhulong.com/";
// JavaScript Document
$(document).ready(function(){
	/*用户名hover*/
	$("#mylname").mouseover(function(){
		$("#mylname_menu").show();
	}).mouseout(function(){
		$("#mylname_menu").hide();
	});

	$("#mylname1").mouseover(function(){
		$("#mylname_menu1").show();
	}).mouseout(function(){
		$("#mylname_menu1").hide();
	});
	/*导航hover*/
	$("#daohang").mouseover(function(){
		$("#mymap_menu").show();
	}).mouseout(function(){
		$("#mymap_menu").hide();
	});

	$("#daohang1").mouseover(function(){
		$("#mymap_menu1").show();
	}).mouseout(function(){
		$("#mymap_menu1").hide();
	});
	$('.zhul_ad_a .zhul_ad_img1').eq(2).addClass('zhul_ad_active');
	$('.zhul_ad_a').mouseover(function(){
		if($(this).find(".zhul_ad_img1").hasClass("zhul_ad_active")){
			return;
		}else{
			$(".zhul_ad_img1").removeClass("zhul_ad_active");
			$(this).find(".zhul_ad_img1").addClass("zhul_ad_active")
		}
		
	}).mouseout(function(){
		
	});
	$("a").live("click",function(e){
		var href=$(this).attr("href");
		if(href.indexOf("user/logout")>-1){
			$.getJSON(ucenter_domain+"/user/logout?callback=?",{},function(){
				window.location.href=window.location.href;
			});
			return false;
		}
	});
});
function kfocus(obj)
{
	if(isInitKey(obj.value)){
		obj.defaultValue=obj.value;
		if(obj.value==obj.defaultValue)
		{
			obj.value='';
			obj.style.color='#000'
		}
	}
}
;(function (){
	$("#loginurl").attr("href","javascript:widow_Loading()"); 
	$("#loginurl1").attr("href","javascript:widow_Loading()"); 
    var username = jQuery.cookie("username");
    if (typeof username!="undefined" && username!=null && username!="")
	{
        $(".zhul_header_nologin").hide();
    	$("#username").html(username+"<img src=\"/img/pubimg/bbs_jiao.png\"/>");
		var uid=jQuery.cookie("uid");
		$("#username").attr('href',"https://passport.zhulong.com/archive");
		$("#userindex").attr('href',"https://passport.zhulong.com/archive");
        $("#zhul_header_login").show();
    }
	else
	{
		$(".zhul_header_edu_nologin").show();
		$("#logout").hide();
	}

	//个人中心更多信息展示
	//console.log($("#user-login"));
	$(".user-info").hover(function(){
		$("#mylname_menu").show();
	},function(){
		$("#mylname_menu").hide();
	});

	/*消息hover*/
	$("#mymassage").mouseover(function(){
		$("#mymessage_menu").show();
	}).mouseout(function(){
		$("#mymessage_menu").hide();
	});
})();

(function (){
	$("#loginurl1").attr("href","javascript:widow_Loading()"); 
    var username = jQuery.cookie("username");
    var bgc = $(".current").attr("wb");
    if (typeof username!="undefined" && username!=null && username!="")
	{
        $(".zhul_header_nologin").hide();
        $("#username1").html(username+"<img src=\"/img/pubimg/bbs_jiao_black.png\"/>");
        // 判断新的筑龙头部应显示什么颜色
        if (bgc == "0") {
        $("#username1").html(username+"<img src=\"/img/pubimg/bbs_jiao.png\"/>");
        // $(".zhul_top1 a").css("color","#fff");
        // $(".zl-logo-new1").css("background","url(../img/pubimg/logo_white.png) center center no-repeat !important")
			// document.write("黑");
		} else if(bgc == "1"){
			// document.write("白");		
        	$("#username1").html(username+"<img src=\"/img/pubimg/bbs_jiao_black.png\"/>");
        	// $(".zhul_top1 a").css("color","#000");
        // $(".zl-logo-new1").css("background","url(../img/pubimg/logo_black.png) center center no-repeat !important")
		}
		var uid=jQuery.cookie("uid");
		$("#username1").attr('href',"https://passport.zhulong.com/archive");
		$("#userindex1").attr('href',"https://passport.zhulong.com/archive");
        $("#zhul_header_login1").show();
    }
	else
	{
		$(".zhul_header_edu_nologin").show();
		$("#logout1").hide();
	}

	//个人中心更多信息展示
	//console.log($("#user-login"));
	$(".user-info").hover(function(){
		$("#mylname_menu1").show();
	},function(){
		$("#mylname_menu1").hide();
	});

	/*消息hover*/
	$("#mymassage").mouseover(function(){
		$("#mymessage_menu1").show();
	}).mouseout(function(){
		$("#mymessage_menu1").hide();
	});
})();

//艺术设计左下轮播图
function sliderStart() {
	var slider_width = ($(".slider_ul li").length + 1) * (76);
	var slider_width1 = ($(".slider_ul li").length-4) * (76);
	$(".slider_ul").width(slider_width);
	//判断当前是否在执行动画
	var is_playing = false;
	var completed = function() {
		is_playing = false;
	}

	$('.xl_banner .flex-prev').click(function() {
		if (!is_playing) {
			var S_left = parseInt($(".slider_ul").css("left").replace('px', ''));
			var leftVal = (S_left +304) + 'px';
			if (S_left < -10) {
				is_playing = true;
				$(".slider_ul").animate({
					left: leftVal
				}, 300, completed);
			}else{
				is_playing = true;
				$(".slider_ul").animate({
					left: '-304px'
				}, 300, completed);
			}
		}
	});

	$('.xl_banner .flex-next').click(function() {
		if (!is_playing) {
			var S_left = parseInt($(".slider_ul").css("left").replace('px', ''));
			var leftVal = (S_left - 304) + 'px';
			if (S_left > -(slider_width1)) {
				is_playing = true;
				$(".slider_ul").animate({
					left: leftVal
				}, 300, completed);
			}else{
				is_playing = true;
				$(".slider_ul").animate({
					left: '0px'
				}, 300, completed);
			}
		}
	});
};
//zhulong index slider（navslider）
function sliderNavStart() {

	var sliderCircle = null;
	$(".slider-nav").find(".nav-item").hover(function() {
	    clearInterval(sliderCircle);

	    $(".slider-nav .nav-item").removeClass("current");
	    $(this).addClass("current");
	    var _bgUrl = $(this).attr("data-bgimg");
	    var _bgColor = $(this).attr("data-bgimg");
	    var _outObj = $(".slider-inner").find(".out");
	    $(".slider-inner").find(".in").removeClass("in").addClass("out");
	    _outObj.css({
	        "background-image": _bgUrl,
	        "background-color": _bgColor
	    }).removeClass("out").addClass("in").attr('href',$(this).attr("href")).attr('title',$(this).attr("title"));
		sliderop();
	}, function() {
	    sliderCircle = setInterval(autoSlider, 6000);
	});

	sliderCircle = setInterval(autoSlider, 6000);

	function autoSlider() {
	    var navLen = $(".nav-item").length;
	    var currentObj = $(".slider-nav").find(".current");
        var _index=$(".nav-item").index($(".current"));
        //console.log(navLen +"  "+_index)
	    if (_index < (navLen - 1)) {
	        $(".slider-nav").find(".current").removeClass("current");
            $(".nav-item").eq(_index+1).addClass("current");
	    } else {
	        $(".slider-nav").find(".current").removeClass("current");
	        $(".slider-nav .nav-item").eq(0).addClass("current");
        if ($(".slider-nav .nav-item").eq(1).hasClass("current")) {
			$(".slider-inner").css("display","none");
			$(".slider-inner_ad").css("display","block");

		}else{
			$(".slider-inner").css("display","block");
			$(".slider-inner_ad").css("display","none");
		}
	    }
	    var _objCurrent = $(".slider-nav").find(".current");
	    var _outObj = $(".slider-inner").find(".out");

	    $(".slider-inner").find(".in").removeClass("in").addClass("out");
	    if(_outObj.length<1){
	    	return ;
	    }
	    _outObj.css({
	        "background-image": _objCurrent.attr("data-bgimg"),
	        "background-color": _objCurrent.attr("data-bgcolor")
	    });
	    _outObj.removeClass("out").addClass("in");
	    _outObj.attr('href',_objCurrent.attr("href"));
	    _outObj.attr('title',_objCurrent.attr("title"));
	    _outObj.attr('alt',_objCurrent.attr("title"));
		sliderop();
	}
};
function sliderop(){
// 判断新的筑龙头部应显示什么颜色
    var bgc = $(".current").attr("wb");
    if (bgc == "1") {
        // alert(12);
        $(".zhul_top1 .youse").css("color","#fff");           
        $(".zhul_tpright1 li").css("color","#fff");           
        $(".zl-logo-new1").css("background","url(/img/pubimg/logo_white.png) center center no-repeat !important");
        $("#username1").find("img:last").attr("src","images/bbs_jiao.png");
        $(".top_more_jiao").css("background","url(images/bbs_jiao.png) no-repeat");
    } else if(bgc == "0"){
        $(".zhul_top1 .youse").css("color","#000");           
        $(".zhul_tpright1 li").css("color","#000");
        $(".zl-logo-new1").css("background","url(/img/pubimg/logo_black.png) center center no-repeat !important");
        $("#username1").find("img:last").attr("src","images/bbs_jiao_black.png");
        $(".top_more_jiao").css("background","url(images/bbs_jiao_black.png) no-repeat");
    }
}
function autoScroll() 
{
    $('.news-scroll').find(".news-scroll-list").animate({
        marginTop: "-22px"
    }, 500, function() {
        $(this).css({
            marginTop: "0px"
        }).find("li:first").appendTo(this);
    });
}
function autoScrollInit(){
    var t=setInterval('autoScroll()', 3000);
    $('.news-scroll').hover(function(){
        clearInterval(t);
    },function(){
        t=setInterval('autoScroll()', 3000);
    })
};
function wwwInit(){
	if($(".side-nav").length==1){
		var href=window.location.href;
        if(href.indexOf("zt")>-1){
            return;
        }
		$.getJSON("https://edu.zhulong.com/openjson/getZhibo?specialty_id="+specialty_id+"&jsoncallback=?",{},function(data){
			if(data.errNo==0){
				$(".side-nav .nava").eq(0).removeClass("mt0");
				$(".side-nav").prepend(data.result);
				// 直播通知隐藏
				var tvshow = 0;
				$('.live-tv').mousemove(function(){
					tvshow = 1;
					$('.live-info').show(500);
				})
				$('.live-tv').mouseout(function(){
					tvshow = 0;
					setTimeout(function(){
						if(tvshow==0){
							$('.live-info').hide(500);
						}
					},500)
				})
				$('.live-info').mousemove(function(){
					tvshow = 1;
					$('.live-info').show();
				})
				$('.live-info').mouseout(function(){
					tvshow = 0;
					setTimeout(function(){
						if(tvshow==0){
							$('.live-info').hide(500);
						}
					},500)
				})
			}else{
				$('.consult_code').css('top','341px');
			}
		})
	}
}

$(wwwInit);
